package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.Answer;
import com.qf.entity.AnswerExample;
import com.qf.mapper.AnswerMapper;
import com.qf.service.AnswerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 10537
 * @version V1.0
 * @Date 2021/10/6 16:41
 */
@Service
public class AnswerServiceImpl implements AnswerService {
    @Autowired
    private AnswerMapper answerMapper;

    @Override
    public PageInfo<Answer> findByPageAndQid(Integer page, Integer rows, Integer qId) {
        AnswerExample example=new AnswerExample();
        AnswerExample.Criteria criteria = example.createCriteria();
        criteria.andQidEqualTo(qId);
        PageHelper.startPage(page,rows);
        List<Answer> answers = answerMapper.selectByExample(example);
        PageInfo<Answer> pageInfo=new PageInfo<>(answers);
        return pageInfo;
    }

    @Override
    public void add(Answer answer) {
        int insert = answerMapper.insert(answer);
        if (insert!=1){
            System.out.println("回答失败");
            throw new RuntimeException("回答失败");
        }
    }
}
